﻿using BCDto.Common.SystemConfiguration;
using BCService.Common.SystemConfiguration;
using BCService.Utils;
using BCTMSRESTful.Configs;
using BCTMSRESTful.Controllers.Management;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;

namespace BCTMSRESTful.Controllers.Management.System.SystemConfiguration
{
    /// <summary>
    /// 系统配置
    /// </summary>
    [ApiExplorerSettings(GroupName = "Admin")]
    [Route("api/v1/sim/[controller]")]
    public class SystemConfigurationController : ManagementBaseController
    {
        private readonly ISystemConfigurationService systemConfigurationService;

        public SystemConfigurationController(ISystemConfigurationService systemConfigurationService)
        {
            this.systemConfigurationService = systemConfigurationService;
        }

        #region 修改系统配置
        /// <summary>
        ///  修改系统配置
        /// </summary>
        /// <param name="systemConfigurationId">系统配置Id</param>
        /// <param name="requestDto">系统配置信息</param>
        /// <response code="200">修改系统配置成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPut("{system_configuration_id}")]
        [Log("修改系统配置")]
        [ProducesResponseType(typeof(SystemConfigurationDto), 200)]
        public IActionResult Put([FromRoute(Name = "system_configuration_id")] int systemConfigurationId, [FromBody] SystemConfigurationRequestDto requestDto)
        {
            SystemConfigurationPutDto putDto = requestDto.As<SystemConfigurationPutDto>();
            putDto.SystemConfigurationId = systemConfigurationId;
            return StatusCode((int)HttpStatusCode.OK, this.systemConfigurationService.Update(putDto));
        }
        #endregion

        #region 获取系统配置
        /// <summary>
        ///  获取系统配置
        /// </summary>
        /// <response code="200">获取系统配置</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(SystemConfigurationDto), 200)]
        public IActionResult Get()
        {
            return StatusCode((int)HttpStatusCode.OK, this.systemConfigurationService.Get());
        }
        #endregion
    }
}
